package com.qqtech.qquan.user.dao;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.qqtech.core.frame.dao.BaseDaoImpl;
import com.qqtech.qquan.user.model.UserFriend;
import com.qqtech.qquan.user.model.UserFriendVo;

@Repository
public class UserFriendDaoImpl extends BaseDaoImpl<UserFriend> implements UserFriendDao {
	public static final Logger log = LoggerFactory.getLogger(UserFriendDaoImpl.class);

	@Override
	public boolean isFriend(Integer userId1, Integer userId2) {
		UserFriend friend = new UserFriend();
		friend.setUserId1(userId1);
		friend.setUserId2(userId2);
		int count = sqlSessionTemplate.selectOne(getSqlName("selectNormalCount2User"), friend);
		return  count > 0;
	}

	@Override
	public List<Integer> queryMyFriendIds(Integer userId) {
		return sqlSessionTemplate.selectList(getSqlName("queryMyFriendIds"), userId);
	}
	
	@Override
	public UserFriendVo queryNormalFriend(Integer userId1, Integer userId2) {
		UserFriend friend = new UserFriend();
		friend.setUserId1(userId1);
		friend.setUserId2(userId2);
		return sqlSessionTemplate.selectOne(getSqlName("selectNormalFriend"), friend);
	}
	
	@Override
	public UserFriendVo queryFriendRecord(Integer userId1, Integer userId2) {
		UserFriend friend = new UserFriend();
		friend.setUserId1(userId1);
		friend.setUserId2(userId2);
		return sqlSessionTemplate.selectOne(getSqlName("selectFriendRecord"), friend);
	}
	
	@Override
	public int removeFriendShip(Integer userId1, Integer userId2) {
		UserFriend friend = new UserFriend();
		friend.setUserId1(userId1);
		friend.setUserId2(userId2);
		return sqlSessionTemplate.update(getSqlName("removeFriendShip"), friend);
	}
	
	@Override
	public int recoveryFriendShip(Integer userId1, Integer userId2) {
		UserFriend friend = new UserFriend();
		friend.setUserId1(userId1);
		friend.setUserId2(userId2);
		return sqlSessionTemplate.update(getSqlName("recoveryFriendShip"), friend);
	}
}
